﻿//-----------------------------------------------------------------------
// <copyright file="ServiceManagerTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using GateShift.Servers.GameServer.Managers.Service;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

#endregion

namespace GateShift.Testing.Servers.GameServer.Managers
{
    /// <summary>
    /// Unit Test Class for ServiceManagerTest
    /// </summary>
    [TestClass]
    public class ServiceManagerTest
    {
        private ServiceManager _manager;
        private ServiceManager_Accessor _accessor;
        private MockFactory _mocks;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        /// <summary>
        /// Use TestInitialize to run code before running each test
        /// </summary>
        [TestInitialize]
        public void TestInitialize()
        {
            _manager = new ServiceManager();
            _accessor = ServiceManager_Accessor.AttachShadow(_manager);
            _mocks = new MockFactory(MockBehavior.Strict);
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run
        /// </summary>
        [TestCleanup]
        public void TestCleanup()
        {
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Test for NormalConstructor on Initializing Variables
        /// </summary>
        [TestMethod]
        public void NormalConstructor_InitializesVariables()
        {
            Assert.IsNotNull(_accessor._services);
            Assert.AreEqual(0, _accessor._services.Count);
            Assert.IsNotNull(_accessor._serviceCommandLines);
            Assert.AreEqual(0, _accessor._serviceCommandLines.Count);
        }

        #endregion

        #region BackGround Threading

        /// <summary>
        /// Test for BackGroundThread on starting and stopping
        /// </summary>
        [TestMethod]
        public void BackGroundThread()
        {
            Assert.AreEqual(false, _manager.IsAlive);
            _manager.Start();
            Assert.AreEqual(true, _manager.IsAlive);
            _manager.Stop();
            Assert.AreEqual(false, _manager.IsAlive);
        }

        #endregion
    }
}